<template>
	<view>
		<up-button type="primary" @click="pullPhone">呼叫</up-button>
	</view>
</template>

<script setup>
	import {
		onLoad,requireNativePlugin
	} from '@dcloudio/uni-app'
	// 引入原生插件
	const TUICallKit =requireNativePlugin('TencentCloud-TUICallKit');
	// 登录TUI组件
	const login = () =>{
		const options = {
		  SDKAppID: 1600073250,   // 请替换为步骤一取到的 SDKAppID
		  userID: '1',        // 请替换为您的 UserID
		  userSig: 'eJyrVgrxCdYrSy1SslIy0jNQ0gHzM1NS80oy0zLBwoZQweKU7MSCgswUJStDMwMDA3NjI1MDiExqRUFmUSpQ3NTU1AgoBREtycwFiZkbW1oaGwIh1JTMdKCZGekZwZneFjH6KRWWUWHp5UHBnu4x*gXphWkmib7ZWa7mlU6eGZXZlj6WAemetkq1AHOMMH0_', // 您可以在控制台中计算一个 UserSig 并填在这个位置
		};
		TUICallKit.login(options, (res) => {
		  if (res.code === 0) {
		    console.log('login success');
		  } else {s
		    console.log(`login failed, error message = ${res.msg}`);
		  }
		});
	}
	onLoad(() => {
		login()
	})
	
	
	// 呼叫
	const pullPhone = () => {
		const options = {
		  userID: '100035149399',
		  callMediaType: 2, // 语音通话(callMediaType = 1)、视频通话(callMediaType = 2)
		};
		TUICallKit.call(options, (res) => {
		  if (res.code === 0) {
		    console.log('call success');
		  } else {
			  console.log(res);
		    console.log(`call failed, error message = ${res.msg}`);
		  }
		});
	}
	
	
	// 接听通话
	const answerCall = () =>{
		const options = {
		  nickName: 'jack',
		  avatar: ''
		}
		TUICallKit.setSelfInfo(options, (res) => {
		  if (res.code === 0) {
		    console.log('setSelfInfo success');
		  } else {
		    console.log(`setSelfInfo failed, error message = ${res.msg}`);
		  }
		});
	};
	
</script>

<style>

</style>